package com.example.a79273.shandianban.fragment;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.a79273.shandianban.AddressActivity;
import com.example.a79273.shandianban.CollectActivity;
import com.example.a79273.shandianban.DesignerFActivity;
import com.example.a79273.shandianban.FootActivity;
import com.example.a79273.shandianban.MoneyqActivity;
import com.example.a79273.shandianban.R;
import com.example.a79273.shandianban.ServiceActivity;
import com.example.a79273.shandianban.SettingActivity;
import com.example.a79273.shandianban.ZpayActivity;
import com.example.a79273.shandianban.application.MyApplication;

/**
 * Created by Administrator on 2016/8/31.
 */
public class MineFragment extends Fragment implements View.OnClickListener{
    View view;
    private ImageView iv_mine_setting, iv_mine_icon;
    private TextView tv_mine_zpay, tv_mine_zsend, tv_mine_zrecevie,
            tv_mine_zcommend,tv_fragment_mine_name;
    private RelativeLayout rl_mine_order, rl_mine_collect, rl_mine_fdesigner,
            rl_mine_moneyq,rl_mine_foot,rl_mine_address,rl_mine_service;
    private Intent intent;
    private MyApplication myApplication;
    private String name;
    private Bitmap icon;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup
            container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_mine, null);
        initView();
        initData();
        setData();
        setListener();
        return view;
    }

    private void setListener() {
        rl_mine_fdesigner.setOnClickListener(this);
        rl_mine_moneyq.setOnClickListener(this);
        rl_mine_order.setOnClickListener(this);
        rl_mine_foot.setOnClickListener(this);
        iv_mine_icon.setOnClickListener(this);
        iv_mine_setting.setOnClickListener(this);
        tv_mine_zcommend.setOnClickListener(this);
        tv_mine_zpay.setOnClickListener(this);
        tv_mine_zrecevie.setOnClickListener(this);
        tv_mine_zsend.setOnClickListener(this);
        rl_mine_address.setOnClickListener(this);
        rl_mine_collect.setOnClickListener(this);
        rl_mine_service.setOnClickListener(this);
    }

    private void setData() {
        if (icon != null && !TextUtils.isEmpty(name)) {
            iv_mine_icon.setImageBitmap(icon);
            tv_fragment_mine_name.setText(name);
        }
    }
    private void initData() {
        myApplication = MyApplication.getInstance();
        name = myApplication.getName();
        icon = myApplication.getIcon();
    }

    private void initView() {
        iv_mine_setting= (ImageView) view.findViewById(R.id.iv_mine_setting);
        iv_mine_icon= (ImageView) view.findViewById(R.id.iv_mine_icon);
        tv_mine_zpay= (TextView) view.findViewById(R.id.tv_mine_zpay);
        tv_mine_zsend= (TextView) view.findViewById(R.id.tv_mine_zsend);
        tv_mine_zrecevie= (TextView) view.findViewById(R.id.tv_mine_zrecevie);
        tv_mine_zcommend= (TextView) view.findViewById(R.id.tv_mine_zcommend);
        tv_fragment_mine_name= (TextView) view.findViewById(R.id.tv_fragment_mine_name);
        rl_mine_order= (RelativeLayout) view.findViewById(R.id.rl_mine_order);
        rl_mine_collect= (RelativeLayout) view.findViewById(R.id.rl_mine_collect);
        rl_mine_fdesigner= (RelativeLayout) view.findViewById(R.id.rl_mine_fdesigner);
        rl_mine_moneyq= (RelativeLayout) view.findViewById(R.id.rl_mine_moneyq);
        rl_mine_foot= (RelativeLayout) view.findViewById(R.id.rl_mine_foot);
        rl_mine_address= (RelativeLayout) view.findViewById(R.id.rl_mine_address);
        rl_mine_service= (RelativeLayout) view.findViewById(R.id.rl_mine_service);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_mine_setting:
                intent = new Intent(getActivity(),SettingActivity.class);

                break;
            case R.id.iv_mine_icon:
                intent=new Intent(getActivity(),SettingActivity.class);
                break;
            case R.id.tv_mine_zpay:
                intent=new Intent(getActivity(),ZpayActivity.class);

                intent.putExtra("zpay","zpay");

                break;
            case R.id.tv_mine_zsend:
                intent=new Intent(getActivity(),ZpayActivity.class);
                intent.putExtra("zsend","zsend");


                break;
            case R.id.tv_mine_zrecevie:
                intent=new Intent(getActivity(),ZpayActivity.class);
                intent.putExtra("zrecevie","zrecevie");

                break;
            case R.id.tv_mine_zcommend:
                intent=new Intent(getActivity(),ZpayActivity.class);
                intent.putExtra("zcommend","zcommend");

                break;
            case R.id.rl_mine_order:
                intent=new Intent(getActivity(),ZpayActivity.class);
                intent.putExtra("all","all");

                break;
            case R.id.rl_mine_collect:
                intent=new Intent(getActivity(),CollectActivity.class);
                break;
            case R.id.rl_mine_fdesigner:
                intent=new Intent(getActivity(),DesignerFActivity.class);
                break;
            case R.id.rl_mine_foot:
                intent=new Intent(getActivity(),FootActivity.class);
                break;
            case R.id.rl_mine_moneyq:
                intent=new Intent(getActivity(),MoneyqActivity.class);
                break;
            case R.id.rl_mine_address:
                intent=new Intent(getActivity(),AddressActivity.class);
                break;
            case R.id.rl_mine_service:
                intent=new Intent(getActivity(),ServiceActivity.class);
                break;
        }
        startActivity(intent);
    }
}
